package com.docking.heylo.web.controller;

import com.docking.heylo.ThreadContext;
import com.docking.heylo.constant.SystemConstant;
import com.docking.heylo.dao.entity.BuddyRecord;
import com.docking.heylo.dao.entity.Post;
import com.docking.heylo.service.IBuddyService;
import com.docking.heylo.utils.HeyloMessageSource;
import com.docking.heylo.web.dto.PostDto;
import com.docking.heylo.web.utils.ResultUtil;
import com.docking.heylo.web.vo.BaseVo;
import javafx.geometry.Pos;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/user/buddy")
public class BuddyController {

    @Autowired
    private IBuddyService buddyService;

    @Autowired
    private HeyloMessageSource ms;


    /***
     * 好友列表
     *
     * @return
     */
    @RequestMapping("/list")
    public BaseVo list(@RequestBody PostDto dto){
        List<Map<String, Object>> list = buddyService.list(dto);
        return ResultUtil.success(ms.getMessage(SystemConstant.success), list);
    }

    /***
     * 超级喜欢
     *
     * @return
     */
    @PostMapping("/veryLike")
    public BaseVo veryLike(@RequestBody Post post){
        buddyService.veryLike(post.getUserId());
        return ResultUtil.success(ms.getMessage("like.success"));
    }

    /***
     * 检查是否是好友
     *
     * @return
     */
    @PostMapping("/check")
    public BaseVo check(@RequestBody BuddyRecord record){
        BuddyRecord br = buddyService.friend(ThreadContext.userId(), record.getUserB());

        // 我太难了
        return ResultUtil.success(ms.getMessage(SystemConstant.success), new HashMap<String, Object>(){{
            put("friend", br != null);
        }});
    }

    /***
     * 拉黑用户
     *
     * @return
     */
    @PostMapping("/report")
    public BaseVo report(@RequestBody Post post){
        buddyService.report(post.getUserId());
        return ResultUtil.success(ms.getMessage(SystemConstant.success));
    }


    /***
     * 检查是否拉黑用户
     *
     * @return
     */
    @PostMapping("/checkReport")
    public BaseVo checkReport(@RequestBody Post post){
        return ResultUtil.success(ms.getMessage(SystemConstant.success),buddyService.checkReport(post.getUserId()) != null);
    }


    /***
     * 黑名单列表
     *
     * @return
     */
    @PostMapping("/blacks")
    public BaseVo blacks(@RequestBody PostDto dto){
        return ResultUtil.success(ms.getMessage(SystemConstant.success),buddyService.blacks(dto));
    }


    /***
     * 取消拉黑
     *
     * @return
     */
    @PostMapping("/removeBlack")
    public BaseVo removeBlack(@RequestBody Post post){
        buddyService.removeBlack(post.getUserId());
        return ResultUtil.success(ms.getMessage(SystemConstant.success));
    }

    /***
     * 解除好友关系
     *
     * @return
     */
    @PostMapping("/disconnect")
    public BaseVo disconnect(@RequestBody Post post){
        buddyService.disconnect(post);
        return ResultUtil.success(ms.getMessage(SystemConstant.success));
    }



















}
